package com.dragon.client.controller.contract;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.contract.IProduceSchedulingService;
import com.dragon.repository.domain.dto.ProduceDTO;
import com.dragon.repository.domain.dto.ProduceSchedulingDTO;
import com.dragon.repository.domain.vo.ProduceSchedulingVO;
import com.dragon.repository.entity.Produce;
import com.dragon.repository.entity.ProduceScheduling;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 生产的排产表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-11-29
 */
@RestController
@RequestMapping("produceScheduling")
@Api(tags = "排产")
public class ProduceSchedulingController {

    @Autowired
    IProduceSchedulingService service;

    @GetMapping("list")
    @ApiOperation(value = "排产列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "条数", required = true, type = "int"),
            @ApiImplicitParam(name = "type", value = "生产状态", required = false, type = "int")
    })
    public ResponseData<List<ProduceSchedulingDTO>> produceSchedulingList(@RequestParam Integer page,
                                                                        @RequestParam Integer limit,
                                                                        @RequestParam(required = false) Integer type){
        Page<ProduceScheduling> produceSchedulePage = service.produceSchedulingList(page, limit, type);
        return ResponseData.success(ProduceSchedulingDTO.convertList(produceSchedulePage.getRecords()), produceSchedulePage.getTotal());
    }


    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseData produceSchedulingAdd(@RequestBody @Validated(Insert.class) ProduceSchedulingVO vo){
        service.produceSchedulingAdd(ProduceSchedulingVO.convert(vo));
        return ResponseData.success();
    }

    @GetMapping("getProduceProduce")
    @ApiOperation(value = "获取生产单和子表信息")
    public ResponseData<List<ProduceDTO>> getProduceList(
            @ApiParam(name = "ids",value = "生产单id集合", required = true, type = "string")
            @RequestParam String ids){
        List<Produce> produceList = service.getProduceList(ids);
        return ResponseData.success(ProduceDTO.convertList(produceList));
    }
}
